package com.hackerrank.contests.regexpractice1.challenges.detectingvalidlatitudeandlongitude;

import java.util.Scanner;

public class Solution {
	private static final String VALID = "Valid", INVALID = "Invalid";
	private static String removeSign(String s) {
		char c = s.charAt(0);
		if(c == '+' || c == '-')
			return s.substring(1);
		return s;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		n: for(int i = 0; i < N; i++) {
			String s = in.nextLine();
			if(s.charAt(0) !='(' || s.charAt(s.length() - 1) != ')') {
				System.out.println(INVALID);
				continue;
			}
			String l[] = s.substring(1, s.length() - 1).split(", ");
			if(l.length != 2) {
				System.out.println(INVALID);
				continue;
			}
			for(int j = 0; j < l.length; j++) {
				l[j] = removeSign(l[j]);
				
				// validate decimal
				int k = l[j].indexOf('.');
				if(k >= 0) {
					if(!l[j].substring(k + 1).matches("[0-9]+")) {
						System.out.println(INVALID);
						continue n;
					}
				}
				
				// validate leading zeros
				int iei = k >= 0 ? k : l[j].length();
				if(!l[j].substring(0, iei).matches("[0-9]+") || iei > 1 && l[j].startsWith("0")) {
					System.out.println(INVALID);
					continue n;
				}
			}
			double lt = Double.parseDouble(l[0]), lg = Double.parseDouble(l[1]);
			if(lt >= 0 && lt <= 90 && lg >= 0 && lg <= 180)
				System.out.println(VALID);
			else
				System.out.println(INVALID);
		}
	}
}
